// 引入全局函数
const app = getApp()
Component({
  /**
   * 组件的初始数据
   */
  data: {
    min_height: 10,
    selected: 0,
    color: "#000",
    selectedColor: "#0099f6",
    backgroundColor: "#F7F8F8",
    list: [{
        pagePath: "/pages/index/index",
        text: "首页",
        iconPath: "/images/tabs/home.png",
        selectedIconPath: "/images/tabs/home-active.png"
      },
      {
        pagePath: "/pages/new/index",
        text: "新闻",
        iconPath: "/images/tabs/new.png",
        selectedIconPath: "/images/tabs/new-active.png"
      },
      {
        pagePath: "/pages/firstwrite/index",
        text: "",
        bulge: true,
        iconPath: "/images/tabs/add.png",
        selectedIconPath: "/images/tabs/add.png"
      },
      {
        pagePath: "/pages/instrument/index",
        text: "工具",
        iconPath: "/images/tabs/instrument.png",
        selectedIconPath: "/images/tabs/instrument-active.png"
      },
      {
        pagePath: "/pages/my/index",
        text: "我的",
        iconPath: "/images/tabs/my.png",
        selectedIconPath: "/images/tabs/my-active.png"
      }
    ]
  },
  
  
  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      // console.log(e);
      const data = e.currentTarget.dataset;
      const url = data.path;
     
      app.globalData.selected = data.index;
      
      // console.log(app.globalData.selected);
      // console.log(url);
      wx.switchTab({
        url,
      })

    }
  },

  lifetimes: {

    // 在组件在视图层布局完成后执行

    ready: function () {
      this.setData({
        selected: app.globalData.selected
      })
      //插槽中可能需要请求接口后更新内容，请求接口后需要在接口中重新设置高度
      if (!this.data.min_height) {
        // 获取tabbar实际的高度
        this.createSelectorQuery().select('.tab-bar').boundingClientRect((res) => {
          this.setData({
            min_height: res.height
          });
        }).exec();
      }
    }
  }

})